package com.loopy.statement;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.Date;
import java.util.Properties;
import java.util.Scanner;

public class Statement_ {
    public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入管理员名字");
        String admin_name = scanner.next();
        System.out.println("请输入管理员名字");
        String admin_pwd = scanner.next();
        Properties properties = new Properties();
        properties.load(new FileInputStream("src\\mysql.properties"));
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String url = properties.getProperty("url");
        String driver = properties.getProperty("driver");
        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, user, password);
//        System.out.println("connection="+connection);
        Statement statement = connection.createStatement();
//        String sql="select id,name,sex,borndate from actor";\
        String sql="SELECT name,pwd from admin WHERE name='"+admin_name+"'and pwd='"+admin_pwd+"'";
        ResultSet resultSet = statement.executeQuery(sql);

//        while (resultSet.next()){
//            int id = resultSet.getInt(1);
//            String name = resultSet.getString(2);
//            String sex = resultSet.getString(3);
//            Date borndate = resultSet.getDate(4);
//            System.out.println(id+"\t"+name+"\t"+sex+"\t"+borndate);
//        }

        if(resultSet.next()){
            System.out.println("恭喜你登陆成功");
        }else {
            System.out.println("登录失败");
        }

        resultSet.close();
        statement.close();
        connection.close();
    }
}
